package com.compose.universally.components

import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.ColorScheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Shapes
import androidx.compose.material3.Typography
import androidx.compose.runtime.Composable
import androidx.compose.runtime.SideEffect
import com.compose.universally.BuilderComposable
import com.google.accompanist.systemuicontroller.rememberSystemUiController

@Composable
fun BaseMaterial(
    isDarkTheme: Boolean = isSystemInDarkTheme(),
    colorScheme: ColorScheme? = null,
    darkColorScheme: ColorScheme = MaterialTheme.colorScheme,
    lightColorScheme: ColorScheme = MaterialTheme.colorScheme,
    shapes: Shapes = MaterialTheme.shapes,
    typography: Typography = MaterialTheme.typography,
    content: BuilderComposable
) {
    val systemColorScheme = when {
        isDarkTheme -> darkColorScheme
        else -> lightColorScheme
    }
    val mColorScheme = colorScheme ?: systemColorScheme
    val systemUiController = rememberSystemUiController()
    SideEffect {
        systemUiController.setSystemBarsColor(
            color = mColorScheme.background, darkIcons = !isDarkTheme
        )
    }
    MaterialTheme(
        colorScheme = mColorScheme, typography = typography, shapes = shapes, content = content
    )
}